//index.js
//获取应用实例
const app = getApp()
const RHOST = "https://matcha.czlanyangyang.com/request/";

Page({
  data: {
    motto: 'Hello World！',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
  },
  //事件处理函数
  bindGym: function () {
    wx.navigateTo({
      url: '../bindGym/bindGym'
    })
  },
  onLoad: function () {
    this.setData({
      userInfo: wx.getStorageSync('userInfo'),
      hasUserInfo: true
    }),
    this.getMemberInfoById();
  },
  /**
  * 生命周期函数--监听页面显示
  */
  onShow: function () {
    var that=this;
    var res = wx.getStorageSync('myGymInfo')
    if (res.NAME != null || res.NAME!=undefined){
      that.setData({
        motto: '你好，' + res.NAME+'！',
      });
    }
  },
  getMemberInfoById:function(){
    wx.request({
      url: 'https://matcha.czlanyangyang.com/request/getMemberInfoById.js',
      data:{
        openId:wx.getStorageSync("openId")
      },
      success:function(res){
        if(res.code==-1){
          wx.showModal({
            title: '错误',
            content: '获取用户健身房信息失败，请绑定健身房信息！',
          })
        }else{
          wx.setStorageSync("myGymInfo", res.data[0])
        }
      }
    })
  }
})
